package com.liang.interview.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liang.interview.api.vo.InterviewQuestionHistoryVO;
import com.liang.interview.server.entity.po.InterviewQuestionHistory;
import com.liang.interview.server.mapper.InterviewQuestionHistoryMapper;
import com.liang.interview.server.service.InterviewQuestionHistoryService;
import com.liang.interview.server.util.LoginUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class InterviewQuestionHistoryServiceImpl extends ServiceImpl<InterviewQuestionHistoryMapper, InterviewQuestionHistory> implements InterviewQuestionHistoryService {

    @Override
    public List<InterviewQuestionHistoryVO> getDetail(Long id) {
        List<InterviewQuestionHistory> list = lambdaQuery()
                .eq(InterviewQuestionHistory::getInterviewId, id)
                .eq(InterviewQuestionHistory::getCreatedBy, LoginUtil.getLoginId())
                .eq(InterviewQuestionHistory::getIsDeleted, 0)
                .list();
        return list.stream().map(item -> InterviewQuestionHistoryVO.builder()
                .score(item.getScore())
                .keywords(item.getKeywords())
                .question(item.getQuestion())
                .answer(item.getAnswer())
                .userAnswer(item.getUserAnswer())
                .build()).collect(Collectors.toList());
    }
}
